package cn.wolfcode.service.impl;

import cn.wolfcode.domain.SysDictType;
import cn.wolfcode.mapper.SysDictTypeMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISysDictTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ClassName SysDictTypeServiceImpl
 * Create by Mike
 * Date 2021/8/1 16:46
 */
@Service
@Transactional
@Setter
@Slf4j
public class SysDictTypeServiceImpl implements ISysDictTypeService {

    @Autowired
    private SysDictTypeMapper sysDictTypeMapper;

    @Override
    public void save(SysDictType sysDictType) {
        sysDictTypeMapper.insert(sysDictType);
    }

    @Override
    public void delete(Long id) {
        sysDictTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(SysDictType sysDictType) {
        sysDictTypeMapper.updateByPrimaryKey(sysDictType);
    }

    @Override
    public SysDictType get(Long id) {
        return sysDictTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysDictType> listAll() {
        return sysDictTypeMapper.selectAll();
    }

    @Override
    public PageInfo<SysDictType> query(QueryObject qo) {

        //使用分页插件,传入当前页,每页显示数量
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());

        List<SysDictType> sysDictTypes = sysDictTypeMapper.selectForList(qo);

        return new PageInfo(sysDictTypes);
    }

    @Override
    public SysDictType queryByType(String type) {
        return sysDictTypeMapper.selectByType(type);
    }
}
